﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;

namespace GiangDay
{
    public partial class Main : DevComponents.DotNetBar.RibbonForm
    {   
        //Biến
        public bool login = false;       //Kiểm tra đăng nhập  
        public DataRow giaovien = null;  //Thông tin người đăng nhập
        DB data = new DB();
        //Khởi tạo
        public Main()
        {
            InitializeComponent();           
        }
        private void Main_Load(object sender, EventArgs e)
        {
            FrLogin frlogin = new FrLogin();
            frlogin.main = this;
            frlogin.ShowDialog();
            if (!login) this.Close();
            else lbLogin.Text = giaovien["TEN_GV"].ToString();
            bt_giangday_Click(sender, e);
        }
        //Kiểm tra form đang mở
        private bool opensubform(Form f)
        {
            foreach (Form fr in Application.OpenForms)
            {
                if (f.Text == fr.Text)
                {
                    fr.Activate();                           
                    return true;
                }
            }
            f.MdiParent = this;          
            f.ShowInTaskbar = false;
            f.WindowState = FormWindowState.Maximized;
            f.MinimizeBox = false;
            f.MaximizeBox = false;
            f.Show();
            return false;
        }       
        private void openDialogForm(Form fr){            
            fr.ShowInTaskbar = false;
            fr.StartPosition = FormStartPosition.CenterParent;
            fr.ShowDialog();
        }       
        //Giáo viên click
        private void bt_giaovien_Click(object sender, EventArgs e)
        {
            FrGiaoVien giaovien = new FrGiaoVien();
            opensubform(giaovien);
        }
        
        //Giảng dạy click
        private void bt_giangday_Click(object sender, EventArgs e)
        {
            FrGiangday giangday = new FrGiangday();
            opensubform(giangday);
        }

        //About Click
        private void bt_about_Click(object sender, EventArgs e)
        {
            FrmAboutme about = new FrmAboutme();           
            this.openDialogForm(about);           
        }

        //Hướng dẫn click
        private void bt_huongdan_Click(object sender, EventArgs e)
        {
            try
            {
                System.Diagnostics.Process.Start("Help.pdf");
            }
            catch (Exception)
            {                
               
            }
           
        }

        //Lớp click
        private void bt_lop_Click(object sender, EventArgs e)
        {
            FrLop fr = new FrLop();
            opensubform(fr);
        }

        //Máy chủ click
       public void bt_Server_Click(object sender, EventArgs e)
        {
            FrServer sv = new FrServer();
            openDialogForm(sv);
        }     

        //Đăng nhập click
        private void bt_login_Click(object sender, EventArgs e)
        {
            FrLogin frlogin = new FrLogin();
            frlogin.main = this;
            frlogin.ShowDialog();           
            if (login == true)
            {
                ribbonPanel_quanlygiangday.Enabled = true;
                ribbonPanel_trogiup.Enabled = true;
                bt_login.Enabled = false;
                bt_logout.Enabled = true;               
            }
           
        }

        //Đăng xuất click
        public void bt_logout_Click(object sender, EventArgs e)
        {
            login = false;
            giaovien = null;
            foreach (Form fr in this.MdiChildren)
            {
                if (fr != this)              
                    fr.Dispose();                
            }
            FormCollection formsList = Application.OpenForms;
            foreach (Form form in formsList)
            {
                if (form != this) form.Close();
            }
            giaovien = null;
            bt_login.Enabled = true;
            bt_logout.Enabled = false;
            ribbonPanel_quanlygiangday.Enabled = false;
            ribbonPanel_trogiup.Enabled = false;          
        }

        private void btKhoahoc_Click(object sender, EventArgs e)
        {
            FrKhoa k = new FrKhoa();
            openDialogForm(k);
        }

        private void btHocvi_Click(object sender, EventArgs e)
        {
            FrHocVi hv = new FrHocVi();
            openDialogForm(hv);
        }
        private void btChucvu_Click(object sender, EventArgs e)
        {
            FrChucVu cv = new FrChucVu();
            openDialogForm(cv);
        }


        //Thoát click
        private void bt_thoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btMonhoc_Click(object sender, EventArgs e)
        {
            FrMonHoc mh = new FrMonHoc();
            openDialogForm(mh);
        }

        private void btChangePass_Click(object sender, EventArgs e)
        {
            FrChangePass cp = new FrChangePass();
            cp.username=giaovien["USERNAME"].ToString();
            openDialogForm(cp);
        }

        private void btHeDaoTao_Click(object sender, EventArgs e)
        {
            FrHeDaoTao hdt = new FrHeDaoTao();
            openDialogForm(hdt);
        }

        private void btCovan_Click(object sender, EventArgs e)
        {
            FrCoVan fr = new FrCoVan();
            openDialogForm(fr);
        }

        private void buttonItem1_Click(object sender, EventArgs e)
        {
          
        }

       
     }
}
